Crate quick_cache
source ·Expand description
Lightweight, high performance concurrent cache. It allows very fast access to the cached items with little overhead compared to a plain concurrent hash table. No allocations are ever performed unless the cache internal state table needs growing (which will eventually stabilize).
Eviction policy
The current eviction policy is a modified version of the Clock-PRO algorithm. It’s “scan resistent” and provides high hit rates, significantly better than a LRU eviction policy and comparable to other state-of-the art algorithms like W-TinyLFU.
Thread safety and Concurrency
Both sync
(thread-safe) and unsync
(non thread-safe) implementations are provided. The latter
offers slightly better performance when thread safety is not required.
Two keys or QK keys
In addition to the standard key->value
cache, a “two keys” cache (key, qey)->value
is also
available for cases where you want a cache keyed by a tuple like (K, Q)
. But due to limitations
of the Borrow
trait you cannot access such keys without building the tuple and thus potentially
cloning K
and/or Q
.
User defined weight
By implementing the Weighter trait the user can define different weights for each cache entry.
Atomic operations
By using the get_or_insert
or get_value_or_guard
family of functions (both sync and async variants
are available, they can be mix and matched) the user can coordinate the insertion of entries, so only
one value is “computed” and inserted after a cache miss.
Hasher
By default the crate uses ahash, which is enabled (by default) via
a crate feature with the same name. If the ahash
feature is disabled the crate defaults to the std lib
implementation instead (currently Siphash13). Note that a custom hasher can also be provided if desirable.
Synchronization primitives
By default the crate uses parking_lot, which is enabled (by default) via
a crate feature with the same name. If the parking_lot
feature is disabled the crate defaults to the std lib
implementation instead.
Modules
- Concurrent cache variants that can be used from multiple threads.
- Non-concurrent cache variants.
Structs
- Cache options. Built with OptionsBuilder.
- Builder for Options.
- Each cache entry weights exactly
1
unit of weight.
Enums
Traits
- Defines the weight of a cache entry.